<template>
  <ul class="radio" :class="{block: conf && conf.block}">
    <li
      v-for="(item, index) in list"
      :key="index"
      :class="{active: item.isActive}"
      @click="selectThis(item)"
    ><i></i><span>{{item.name}}</span></li>
  </ul>
</template>
<script>
export default {
  name: "radio",
  props: ["conf"],
  computed:{
    list(){return this.conf.list},
    isAllSelected(){
      return this.list.length && this.list.length === this.list.filter(item => item.isActive).length;
    },
    isSomeSelected(){
      return !this.isAllSelected && this.list.some(item => item.isActive);
    },
  },
  methods: {
    selectThis(thisItem){
      const isAllSelected = this.isAllSelected;
      this.list.forEach(item => (item.isActive = item === thisItem))
    }
  },
}
</script>
<style scoped>
.radio{
  display: flex;
  padding: 2px 0;
  flex-wrap: wrap;
}
.radio.block{
  flex-direction: column;
}
.radio.block li{
  padding: 2px 0px
}
.radio li{
  padding: 2px 10px;
  white-space: nowrap;
}
.radio li>*{
  vertical-align: middle;
}
.radio li i{
  display: inline-block;
  position: relative;
  padding-right: 8px;
  height: 16px;
}
.radio li i:before{
  content: "";
  display: inline-block;
  border: 1px solid #ccc;
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  transition: all .3s;
  border-radius: 8px;
}

.radio li.half i:before,
.radio li.active i:before{
  background-color: red;
  border: 1px solid red;
}
.radio li i:after{
  top: 38%;
  left: 33%;
  transform: translate(-50%,-50%) rotate(-45deg);
  content: "";
  display: block;
  position: absolute;
  width: 8px;
  height: 4px;
  border: 2px solid #fff;
  border-top: 0;
  border-right: 0;
  opacity: 0;
  transition: all .3s;
}
.radio li.active i:after{
  opacity: 1;
}
</style>
